/**
 * 
 * 
 */
package com.cjfather.redis.steam.fury;

import java.util.HashMap;
import java.util.HashSet;
import java.util.Set;

import com.cjfather.redis.steam.controller.PropellingInfo;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;

import io.fury.Fury;
import io.fury.Language;
import io.fury.serializer.CompatibleMode;

/**
 * @author: todd
 * @date:   2023年8月30日
 */
public class TestFurySerializer {
	public final static Fury fury = Fury.builder()
		    .withLanguage(Language.JAVA)
		    //开启共享引用/循环引用支持，不需要的话建议关闭，性能更快
		    .withRefTracking(true)
		    // 允许序列化未注册类型
		    // .withClassRegistrationRequired(false)
		    // 开启int/long压缩，减少序列化数据大小，无该类需求建议关闭，性能更好
		    // .withNumberCompressed(true)
		    .withCompatibleMode(CompatibleMode.SCHEMA_CONSISTENT)
		    // 开启类型前后兼容，允许序列化和反序列化字段不一致，无该类需求建议关闭，性能更好
		    // .withCompatibleMode(CompatibleMode.COMPATIBLE)
		    // 开启异步多线程编译
		    .withAsyncCompilation(true)
		    .requireClassRegistration(false)
//		    .buildThreadSafeFury();
		    .build();
	
	public static void main(String[] args) {
		
		Gson gson = new GsonBuilder().create();

		HashMap<String, Object> bodyMap = new HashMap<>();
        bodyMap.put("body", "aaa");
        bodyMap.put("type", "fire");
        bodyMap.put("modules", new String[]{"xjwbWebsocket"});
        
        Set<String> userIds = new HashSet<>();
        userIds.add("1");
        userIds.add("2");
        
        PropellingInfo propellingInfo = new PropellingInfo();
        propellingInfo.setPropellType("WEBSOCKET");
        propellingInfo.setWebsocketUserIds(userIds);
        propellingInfo.setWebsocketContent(gson.toJson(bodyMap));
        
		byte[] bytes = fury.serialize(propellingInfo);
		System.out.println(fury.deserialize(bytes));
	}

}
